﻿@using LanDBom.Resources
@using LanDBom.Models
@{
    ViewBag.Title = "Material_Classification";
}

<h2>Material_Classification</h2>

<from>
    <div>
        <fieldset class="boun nav" style="padding-bottom:6px;">
            <legend class="len">@Resource.String1235</legend>
            <div class="col-lg-3">一级分类:<input type="text" style="width:150px;" id="txtid" /></div>
            <div class="col-lg-3">二级分类:<input type="text" style="width: 150px;" id="txtname" /></div>
            <div calss="col-lg-1"><button id="find_E" class="btn-sm  btn-secondary">@Resource.String1239</button></div>
        </fieldset>
    </div>
    <div><button class="btn" id="xzwlzl">新增物料种类</button></div>
    <table class="table gun tab" style="text-align:center">
        <thead>
            <tr>
                <td>序号</td>
                <td>一级分类</td>
                <td>二级分类</td>
                <td>管理</td>
            </tr>
        </thead>
        <tbody id="E_tb_e1" style="height:500px">
        </tbody>
    </table>

    <div id="show_shangc" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;width:500px;height:300px">
        <div style="text-align: right; background-color: #84acde;"><span class="QUED_quxiao" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        
        <div style="background-color: #fff;">
            <div id="DE_id" style="display:none"></div>
            <table style="width:100%">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>一级分类</th>
                        <th>二级分类</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td></td>
                        <td>
                            <select id="dl_wl" >
                                <option value="0">请选择</option>
                                @foreach (var item in ViewBag.temp2 as List<buty3>)
                                {
                                    <option value="@item.zl2_id">@item.zl2_name</option>
                                }
                            </select>
                        </td>
                        <td>
                            <input type="text" id="name" />
                        </td>
                        <td>
                            <a id="tianj" href="#">添加</a>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </div>

        <div style="text-align:center;height:10%"><button class="QUED_quxiao">@Resource.String126</button></div>
    </div>

</from>


@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            GetEmployee()
            //打开权限管理
            $(document).on("click", "#CG_qxgl", function (e) {
                var id = $(e.target).parent().prev().text()
                var name = $(e.target).parent().parent().children().eq(3).text()
                var name2 = $(e.target).parent().parent().children().eq(2).text()
                console.log(id, name, name2)
                $("#show_shangc").css({ "display": "block" })
                $("#DE_id").text(id)
                $("#dl_wl").val(name)
                $("#name").val(name2)
            })
            $(document).on("click", "#xzwlzl", function (e) {
                $("#show_shangc").css({ "display": "block" })
            })


            //关闭权限管理
            $(document).on("click", ".QUED_quxiao", function (e) {
                $("#show_shangc").css({ "display": "none" })
                $("#DE_id").text("")
                $("#dl_wl").val("")
                $("#name").val("")
            })


            //删除权限
            $(document).on("click", "#CG_scqx", function (e) {
                var id = $(e.target).parent().parent().children().eq(0).text()
                $.ajax({
                    url: '/Admin/Purchasing_Authority',
                    type: 'GET',
                    data: { "id": id, "state": 3 },
                    success: function (data) {
                        alert(data)
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            })


            //添加权限
            $(document).on("click", "#tianj", function (e) {
                var name = $("#name").val()
                var id = $("#dl_wl").val()
                var BZJG = []
                BZJG.push({
                    zl2_id: id,
                    zl_name: name
                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                $.ajax({
                    url: "/Admin/AddNdardo_",
                    type: 'POST',
                    data: JSON.stringify(BZJG),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                        alert(text)
                        Getquanx()
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            })


            

            //查找员工的方法
            function GetEmployee() {
                var name = $("#txtname").val()
                var id = $("#txtid").val()
                var standing = $("#txtstanding").val()
                $.ajax({
                    url: '/Admin/Material_Classification',
                    type: 'GET',
                    data: { "id": id, "name": name, "standing": standing, "state": 1 },
                    success: function (data) {
                        createRow(data)
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }

            //打印员工的方法
            function createRow(data) {
                $('#E_tb_e1 tr').remove();
                var index=1
                $.each(data, function (i, item) {
                    var $tr = $(`
                                                <tr>
                                                    <td id="E_name_e1">${index}</td>
                                                    <td id="E_shenf_e1">${item.zl2_i}</td>
                                                    <td id="E_bu_e1">${item.zl_name}</td>
                                                    <td style="display:none">${item.zl2_id}</td>
                                                    <td style="display:none">${item.zl_id}</td>
                                                    <td><a href="#" id="CG_qxgl">修改</a></td>
                                                </tr>
                                            `);
                    $('#E_tb_e1').append($tr);
                    index++
                })
            }
        })
    </script>
}